[#ftl]
[@define "agile.MetadataEditorTabPane" "agile.MetadataEditorPane"]
	templateString:"<div style='width:100%;height:100%'><div class='editorContainer' data-dojo-type='dijit/layout/TabContainer' data-dojo-props=\"style:'width:100%;height:100%;',tabPosition:'top'\"></div></div>"
	,elementConfig:null
	,metadataEntry:null
	,constructor:function(){		
		this.subscribe("agile.widget.changed."+this.category,function(name,value){
			var editor = this.editorWidgets[name];
			if(editor){
				editor.reset1("value",value);
			}			
		});
	}
	,postCreate:function(){		
		this.domNode.innerHTML = this.templateString;	
		parser.parse(this.domNode);    	
		this.editorContainer = registry.byNode(query(".editorContainer",this.domNode)[0]);
//		this.simpleEditorContainer = registry.byNode(query(".simpleEditorContainer",this.domNode)[0]);
		this.renderEditors();
	}
	,onWidgetSelected:function(widget){		
		this.renderEditors(widget);
				
		if(widget != null){			
			this.setEditorValue(widget);			
		}
	}
	,renderEditors:function(widget){		
		var elements = this.elementConfig;
		if(!this._editorCreated){
			this._editorCreated = true;			
			for(var name in elements){
				var metadata = elements[name];				
				var editor = agile.EditorFactory.lookupEditorWidget(metadata,this);
				//lang.mixin(this.editorWidgets,editor.getEditors());
				this.editorWidgets[name] = editor;
				var child = new ContentPane({title:metadata.label});
				child.set("content",editor);
				this.editorContainer.addChild(child);
			}			
			//console.log("this.editorWidgets:",this.editorWidgets);
		}else{
//			//console.log("###this.editorWidgets:",this.editorWidgets);
			for(var name in this.editorWidgets){
				this.editorWidgets[name].initialize(elements[name],this);
			}
		}
		
		//hide the editor if it is not applicable to the current widget
//		var constraints = metadata[this.metadataEntry+"Constraints"];
//		if(constraints && !constraints.ignore(widget)){
//			//child.set("hidden",true);
//			style.set(child.domNode,{display:"none"});
//		}else{
//			this.editorContainer.addChild(child);	
//		}
	}
	,setEditorValue:function(widget){		
//		console.error(this.declaredClass,"setEditorValue.....style=",widget.metadata("style"));
		for (var name in this.editorWidgets){
//			//console.log(this.declaredClass,name,widget.metadata(name));
			this.editorWidgets[name].reset1("value",widget.metadata(this.metadataEntry));
		}		
	}
[/@] 